package com.zygh.lz.task;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.zygh.lz.controller.app.APPPushNotifications;
import com.zygh.lz.service.BrigadeRecordService;
import com.zygh.lz.service.SignService;
import com.zygh.lz.service.impl.PoliceDataService;
import com.zygh.lz.util.DataTime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class JieChuTask {

    @Resource
    private APPPushNotifications appPushNotifications;
    @Resource
    private BrigadeRecordService brigadeRecordService;
    @Resource
    private PoliceDataService policeDataService;

    @Resource
    private SignService signService;


    //定时获取信大捷安token 两小时过期，50分钟更新一次
    @Async
    @Scheduled(cron = "0 0/50 * * * ? ")
    public void task5() {
        log.info("《《《《《《《《《《《《定时获取信大捷安token");
        appPushNotifications.sendPushMsgByToken();
    }

    //每天早上六点统计昨天效能考核数据 放在签到详情数据统计之后
    @Async
    @Scheduled(cron = "00 40 08 * * ? ")
    public void task1() {
        log.info("《《《《《《《《每天早上六点统计昨天效能考核数据");
        brigadeRecordService.efficiencyData(null, null);
    }


    //统计接处警数据 30分钟一次
    @Async
    @Scheduled(cron = "0 0/30 * * * ? ")
    public void task2() {
        log.info("30分钟插入一次接处警数据");
        policeDataService.manager(null, null);
    }

    //更新接处警数据   两个个小时一更新》》》》》两小时之前-当前时间的数据
    @Async
    @Scheduled(cron = "0 0/55 * * * ? ")
    public void task3() {
        log.info("55分钟更新一次三小时前的数据");
        String startTime = DateUtil.offset(DateUtil.parse(DateUtil.now()), DateField.HOUR, -5).toString();
        String endTime = DateUtil.now();
        policeDataService.manager(startTime, endTime);

    }


    //每天早上七点四十统计前一天数据
    @Async
    @Scheduled(cron = "00 35 08 * * ? ")
    public void task4() {
        log.info("详情数据统计");
        signService.Statistics(null, null);
    }

    //每天一个小时，统计一遍当天的数据
    @Async
    @Scheduled(cron = "0 0/59 * * * ? ")
    public void task9() {
        log.info("详情数据统计");
        signService.Statistics(DataTime.getStartTheDay(), DateUtil.now());
    }

    //每天早上七点四十统计前一天数据,生成的数据在sign_general表中查看
    @Async
    @Scheduled(cron = "00 40 07 * * ? ")
    public void task6() {
        log.info("全局数据统计");
        signService.General(null, null);
    }


}